//
//  VCOfRegister.m
//  02_Homework
//
//  Created by 徐昊 on 16/7/16.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "VCOfRegister.h"
#import "ImgTextFieldView.h"

#define WIDTH registBackImage.bounds.size.width
@interface VCOfRegister ()<UITextFieldDelegate>

@end

@implementation VCOfRegister

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self config];
    
}
- (void)config {
    self.view = [[UIView alloc] init];
    self.view.backgroundColor = [UIColor whiteColor];
    UIImageView *registBackImage = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [registBackImage setImage:[UIImage imageNamed:@"welcome_2"]];
    [self.view addSubview:registBackImage];
    /** 拉钩图标 */
    UIImageView *photoView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 2 - 65, 70, 130, 130 * 296 / 184)];
    [photoView setImage:[UIImage imageNamed:@"logo_lagou"]];
    [registBackImage addSubview:photoView];
    /** 手机号,验证码 */
    ImgTextFieldView *phoneNumber = [[ImgTextFieldView alloc] initWithFrame:CGRectMake(15, 300, WIDTH - 30, 50) image:[UIImage imageNamed:@"11"] placeHolder:@"请输入手机号"];
    [self.view addSubview:phoneNumber];
    phoneNumber.textField.delegate = self;
    phoneNumber.textField.tag = 5;
    phoneNumber.imageView.tag = 50;
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:phoneNumber.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = phoneNumber.bounds;
    maskLayer.path = maskPath.CGPath;
    phoneNumber.layer.mask = maskLayer;
    
    ImgTextFieldView *code = [[ImgTextFieldView alloc] initWithFrame:CGRectMake(15, 352, WIDTH - 30, 50) image:[UIImage imageNamed:@"222"] placeHolder:@"请输入验证码"];
    [self.view addSubview:code];
    code.textField.delegate = self;
    code.textField.tag = 6;
    code.imageView.tag = 60;
    
    UIBezierPath *codeMaskPath = [UIBezierPath bezierPathWithRoundedRect:code.bounds byRoundingCorners:UIRectCornerBottomRight | UIRectCornerBottomLeft cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *codeMaskLayer = [[CAShapeLayer alloc] init];
    codeMaskLayer.frame = code.bounds;
    codeMaskLayer.path = codeMaskPath.CGPath;
    code.layer.mask = codeMaskLayer;
    
    /** 获取验证码 */
    UIButton *getCode = [UIButton buttonWithType:UIButtonTypeSystem];
    [getCode setTitle:@"获取验证码" forState:UIControlStateNormal];
    getCode.frame = CGRectMake(0, 0, 100, 50);
    getCode.titleLabel.font = [UIFont systemFontOfSize:19];
    [getCode setTitleColor:[UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00] forState:UIControlStateNormal];
    [code.textField setRightView:getCode];
    code.textField.rightViewMode = UITextFieldViewModeAlways;
    
    /** 注册, 返回登录按钮 */
    UIButton *regist = [UIButton buttonWithType:UIButtonTypeSystem];
    regist.frame = CGRectMake( 15, 480, WIDTH - 30, 50);
    regist.backgroundColor = [UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00];
    [regist setTitle:@"注册" forState:UIControlStateNormal];
    regist.titleLabel.font = [UIFont systemFontOfSize:20];
    [regist setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [regist addTarget:self action:@selector(regist) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:regist];
    [regist.layer setCornerRadius:10.0];
    
    UIButton *returnVC = [UIButton buttonWithType:UIButtonTypeSystem];
    returnVC.frame = CGRectMake( 15, 550, WIDTH - 30, 50);
    returnVC.backgroundColor = [UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00];
    returnVC.alpha = 0.5;
    [returnVC setTitle:@"返回登录" forState:UIControlStateNormal];
    returnVC.titleLabel.font = [UIFont systemFontOfSize:20];
    [returnVC setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [returnVC addTarget:self action:@selector(returnVC) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:returnVC];
    [returnVC.layer setCornerRadius:10.0];
    
    /** 右上角的关闭 */
    UIButton *close = [UIButton buttonWithType:UIButtonTypeSystem];
    close.frame = CGRectMake(WIDTH - 50, 20, 30, 30);
    [close setImage:[UIImage imageNamed:@"00"] forState:UIControlStateNormal];
    [close addTarget:self action:@selector(returnVC) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:close];
    
    /** 协议文字部分 */
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake((WIDTH - 140) / 2 - 60, 410, 136, 30)];
    label.textColor = [UIColor whiteColor];
    label.text = @"注册代表你已同意";
    [self.view addSubview:label];
    
    /** 协议button部分 */
    UIButton *agreement = [UIButton buttonWithType:UIButtonTypeSystem];
    agreement.frame = CGRectMake((WIDTH - 140) / 2 + 75, 410, 110, 30);
    [agreement setTitle:@"拉钩用户协议" forState:UIControlStateNormal];
    agreement.titleLabel.font = [UIFont systemFontOfSize:17.5];
    [agreement setTitleColor:[UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00] forState:UIControlStateNormal];
    [self.view addSubview:agreement];
    
}

- (void)returnVC {
    [self.navigationController popViewControllerAnimated:YES];
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField.tag == 5) {
        UIImageView *i = [self.view viewWithTag:50];
        [i setImage:[UIImage imageNamed:@"111"]];
    }
    if (textField.tag == 6) {
        UIImageView *i = [self.view viewWithTag:60];
        [i setImage:[UIImage imageNamed:@"22"]];
    }
    return YES;
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    if (textField.tag == 5) {
        UIImageView *i = [self.view viewWithTag:50];
        [i setImage:[UIImage imageNamed:@"11"]];
    }
    if (textField.tag == 6) {
        UIImageView *i = [self.view viewWithTag:60];
        [i setImage:[UIImage imageNamed:@"222"]];
    }
    return YES;
}

- (void)regist {
    NSLog(@"没实现, 总点什么点?");
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField endEditing:YES];
    return YES;
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
